package com.lzb.watermarkcamera.activity;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.watermarkcamera.BaseAc;
import com.lzb.watermarkcamera.Content;
import com.lzb.watermarkcamera.R;
import com.lzb.watermarkcamera.databinding.ActivityInputTextBinding;

public class InputTextActivity extends BaseAc<ActivityInputTextBinding> implements View.OnClickListener {

    private int type;

    @Override
    protected int onCreate() {
        return R.layout.activity_input_text;
    }

    @Override
    protected void initView() {
        mDataBinding.ivInputTextBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvCompelete.setOnClickListener(this);
        mDataBinding.tvTitle.setOnClickListener(this);
        mDataBinding.tvText.setOnClickListener(this);
        mDataBinding.tvClear.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvCompelete) {//完成
            String text = mDataBinding.etContent.getText().toString();
            if (TextUtils.isEmpty(text)) {
                ToastUtils.showShort(getString(R.string.please_input_content));
                return;
            }
            Intent intent = new Intent();
            intent.putExtra(Content.text, text);
            if (type == 0) {
                setResult(Content.ADD_TITLE_RESULT, intent);
            } else {
                setResult(Content.ADD_TEXT_RESULT, intent);
            }
            finish();
        } else if (id == R.id.tvTitle) {//标题
            clearSelection();
            type = 0;
            mDataBinding.tvTitle.setTypeface(Typeface.DEFAULT_BOLD);
            mDataBinding.tvTitle.setTextSize(16);
        } else if (id == R.id.tvText) {//正文
            clearSelection();
            type = 1;
            mDataBinding.tvText.setTypeface(Typeface.DEFAULT_BOLD);
            mDataBinding.tvText.setTextSize(16);
        }else if (id==R.id.tvClear){//清空
            mDataBinding.etContent.setText("");
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.tvTitle.setTypeface(Typeface.DEFAULT);
        mDataBinding.tvTitle.setTextSize(14);
        mDataBinding.tvText.setTypeface(Typeface.DEFAULT);
        mDataBinding.tvText.setTextSize(14);
    }
}